home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software 2000
/
Software 2000 Volume 1 (Disc 1 of 2).iso
/
utilities
/
u130.dms
/
u130.adf
/
Configs
/
SetPrefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-02
|
5KB
|
187 lines
/** SetPrefs.c
*
* SetPrefs, Copyright (C) 1987 by W.G.J. Langeveld
*
* Description:
* ------------
* Have you ever had the problem that you reassigned all your system
* directories to your hard disk or to another floppy or to your re-
* coverable ram disk, and at some point changed and saved your Pre-
* ferences, but to the wrong place? So that when you have to boot
* you wind up with the same old preferences that AmigaDOS picks up
* from the system-configuration file on the floppy you boot from?
* If so, this is a program for you. You run it in your startup-
* sequence AFTER you have reassigned especially devs: to your other
* device. This program will then read the system-configuration file
* in the new devs: directory and set your default preferences accor-
* dingly.
* Moreover, if you just want to use the preferences from some
* other disk or file, you can specify it on the command line: in
* that case the program will search for the specified file rather
* than 'devs:system-configuration'.
*
* Examples of use:
* ----------------
* (1) A sample startup-sequence might look like:
*
* assign C: hd0:c
* assign S: hd0:s
* assign L: hd0:l
* assign FONTS: hd0:fonts
* assign DEVS: hd0:devs
* assign LIBS: hd0:libs
* assign SYS: hd0:
*
* echo "Everything reassigned"
*
* SetPrefs
*
* (2) Suppose I would like to have the colors I get when booting from
* my DrofNats program disk, but don't want to boot from it. I could
* either get into Preferences and set the colors from memory, or I
* could type from the CLI:
*
* 1> SetPrefs DrofNats:devs/system-configuration
*
* If the DrofNats disk is not in a drive, AmigaDOS will prompt you
* to insert it.
*
* (3) Suppose I have a hard disk (I don't) but would like to change the
* set-up on occasion, because e.g. sometimes I use a different
* monitor than other times. One might have several system-configura-
* tion files stashed away someplace, and change to any one of them
* by typing from the CLI:
*
* 1> SetPrefs :configfiles/config25
*
* You can make config files by going into preferences, saving them
* and copying the resulting system-configuration file (Preferences
* always writes to devs:system-configuration):
*
* 1> copy devs:system-configuration :configfiles/config25
*
*
* Have fun!
* Willy.
*
**/
#include "exec/exec.h"
#include "intuition/intuition.h"
#include "libraries/dos.h"
#include "functions.h"
#include "stdio.h"
struct IntuitionBase *IntuitionBase = NULL;
struct Preferences *prefs = NULL, *nprefs = NULL;
FILE *fp = NULL;
char sysconf[] = "devs:system-configuration";
long dos_lenfil();
#define PSIZE ((long) sizeof(struct Preferences))
main(argc, argv)
int argc;
char **argv;
{
int nread;
long length;
char *conffil;
if (argc > 2) cleanup("Usage: %s [file-name]\n", argv[0]);
/*
* Get Intuition
*/
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", NULL);
if (IntuitionBase == NULL) cleanup("Couldn't open Intuition\n", NULL);
/*
* Allocate a Preferences structure
*/
prefs = (struct Preferences *) AllocMem(PSIZE, NULL);
if (prefs == NULL) cleanup("Out of memory\n", NULL);
/*
* If commandline argument, find supplied file, otherwise find standard
* config file.
*/
if (argc <= 1) conffil = sysconf;
else conffil = argv[1];
fp = fopen(conffil,"r");
if (fp == NULL) cleanup("Couldn't find %s\n", conffil);
/*
* Make sure it is a config file by checking its length
*/
length = dos_lenfil(conffil);
if (length != PSIZE) cleanup("%s is not a configuration file??\n", conffil);
/*
* Read it in.
*/
nread = fread(prefs, 1, (int) PSIZE, fp);
/*
* If error during read, this is the last chance to get out.
*/
if (nread != (int) PSIZE) cleanup("Error reading %s\n", conffil);
/*
* Okay, set the new preferences.
*/
SetPrefs(prefs, PSIZE, 1L);
/*
* Cleanup
*/
cleanup(NULL, NULL);
}
/**
*
* Clean up.
*
**/
cleanup(string1, string2)
char *string1, *string2;
{
if (string1 && string2) printf(string1, string2);
else if (string1) printf(string1);
if (prefs) FreeMem(prefs, PSIZE);
if (IntuitionBase) CloseLibrary(IntuitionBase);
if (fp) fclose(fp);
exit(0);
}
long dos_lenfil(filnam)
/**
*
* Routine to get the length of file 'filnam'
*
**/
char filnam[];
{
struct FileInfoBlock *fileinfo;
struct Lock *lunin_lock;
long size;
/*
* Reserve space for the file info block
*/
fileinfo = (struct FileInfoBlock *)
AllocMem((long) sizeof(struct FileInfoBlock),0L);
lunin_lock = Lock(filnam,ACCESS_READ);
Examine(lunin_lock,fileinfo);
size = fileinfo->fib_Size;
UnLock(lunin_lock);
FreeMem(fileinfo,(long) sizeof(struct FileInfoBlock) );
return(size);
}